package com.osdp.startup;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

/**
 *  java -jar micro-client/target/micro-gateway-0.0.1-SNAPSHOT.jar
 *  java -jar target/micro-gateway-0.0.1-SNAPSHOT.jar
 *  https://spring.io/guides/gs/spring-cloud-loadbalancer/
 *
 *  https://spring.io/projects/spring-cloud
 *
 *  spring-cloud调用服务有两种方式，一种是Ribbon+RestTemplate, 另外一种是Feign。
 *  参考： https://blog.csdn.net/lettuce_/article/details/106378110
 *  Ribbon是一个基于HTTP和TCP客户端的负载均衡器，其实feign也使用了ribbon, 只要使用@FeignClient时，ribbon就会自动使用
 *
 * @author lb
 */
@SpringBootApplication(scanBasePackages = "com.osdp")
//@Import({RoutesHandler.class, AdditionalRoutes.class})
@EnableFeignClients(value = {"com.osdp.*.feign"})
@EnableScheduling
@ComponentScan(basePackages = "com.osdp.gateway")
@EnableDiscoveryClient
public class MicroGatewayApplication {

	public static void main(String[] args) {
		SpringApplication.run(MicroGatewayApplication.class, args);
	}

	@Bean
	@LoadBalanced
	public RestTemplate restTemplate(){
		return  new RestTemplate();
	}
}
